package week2.mapreduce;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class FlowReducer extends Reducer<Text, bean, Text, bean> {
    @Override
    protected void reduce(Text key, Iterable<bean> values, Reducer<Text, bean, Text, bean>.Context context) throws IOException, InterruptedException {
        long upFlowSum = 0;
        long dowmFlowSum = 0;
        for (bean flow:values) {
            upFlowSum += flow.getUpflow();
            dowmFlowSum += flow.getDownflow();
        }
        bean valueOut = new bean(upFlowSum, dowmFlowSum);
        context.write(key, valueOut);
    }
}
